
function[fejer] = fejer1999(f107,season, lt,longitude )

% Load the Excel file from Fejer, with the values of
% Scherliess-Fejer model (1999). Idea is to create a 5D
% array which then can be used to evaulate the model
% for any local time, date , longitude and solar flux (f10.7)
% The xls files are
% FinalModel100.xls  FinalModel140.xls  FinalModel180.xls  
% FinalModel110.xls  FinalModel150.xls  FinalModel190.xls  
% FinalModel120.xls  FinalModel160.xls  FinalModel200.xls  
% FinalModel130.xls  FinalModel170.xls 

% filepath = '/home/mnair/projects/ace_tensor/ScherliessFejer1999Model/';
% 
% s = dir([filepath '*.xls']);
% 
% for i=1:length(s),
%     
%     [a] = xlsread([filepath s(i).name]);
%     K = sum(isnan(a),2);
%     a(K==25,:) = [];
%     
%     b(1,:,:) = a(2:59,2:end); % Nov-Feb 1
%     b(2,:,:)= a(61:118,2:end); % Equinox (Mar-Apr) 4
%     b(3,:,:) = a(120:177,2:end); % May - Aug 7
%     b(4,:,:) = a(61:118,2:end); % Equinox (Sep-Oct) 10
%     b(5,:,:) = a(2:59,2:end); % Nov-Feb 13
%     b(6,:,:)= a(61:118,2:end); % Equinox (Mar-Apr) 4
%         
%     for j = 1:6,
%         
%     Fejer1999(i,j,2:59,2:25) = b(j,:,:);
%     Fejer1999(i,j,1,2:25) = b(j,58,:);
%     Fejer1999(i,j,60,2:25) = b(j,1,:);
%     Fejer1999(i,j,:,1) = Fejer1999(i,j,:,25);
%     Fejer1999(i,j,:,26) = Fejer1999(i,j,:,2);
%     
%     end;
%     
%             
% end;
% 
% %%
% dim1_f107 = [100,110,120,130,140,150,160,170,180,190,200];
% %Dec Equinox, Mar Soltice, June Solstice, Sep Equinox, Dec Soltstice 
% dim2_season = [-0.0274, 0.2164, 0.4685, 0.7260, 0.9726,1.2164 ];
% dim3_lt = [-0.50,0, 0.50,  1.00,  1.50,  2.00,  2.50,  3.00,  3.50,  4.00,  4.50,  5.00,  5.50,  6.00,  6.50,  7.00,  7.50,  8.00,  8.50,  9.00,  9.50, 10.00, 10.50, 11.00, 11.50, 12.00, 12.50, 13.00, 13.50, 14.00, 14.50, 15.00, 15.50, 16.00, 16.50, 17.00, 17.25, 17.50, 17.75, 18.00, 18.25, 18.50, 18.75, 19.00, 19.25, 19.50, 19.75, 20.00, 20.25, 20.50, 20.75, 21.00, 21.25, 21.50, 21.75, 22.00, 22.50, 23.00, 23.50, 24.0];
% dim4_longitude = [-195.0 -180.00 -165.00 -150.00 -135.00 -120.00 -105.00 -90.00 -75.00 -60.00 -45.00 -30.00 -15.00  0.00 15.00 30.00 45.00 60.00 75.00 90.00 105.00 120.00 135.00 150.00 165.00 180.00];
% 
%  save /home/mnair/projects/ace_tensor/ScherliessFejer1999Model/Fejer1999.mat
% %% Test the model

load /home/mnair/projects/ace_tensor/ScherliessFejer1999Model/Fejer1999.mat;

WMM_F_600_km = [ 25510, 25470, 25434, 25399, 25362, 25325, ...
			25287, 25249, 25210, 25170, 25132, 25092, 25051, 25010, 24968, ...
			24927, 24884, 24842, 24799, 24756, 24714, 24671, 24628, 24586, ...
			24543, 24501, 24459, 24417, 24375, 24333, 24292, 24250, 24209, ...
			24168, 24128, 24087, 24047, 24006, 23966, 23926, 23886, 23846, ...
			23806, 23766, 23726, 23685, 23645, 23605, 23565, 23524, 23483, ...
			23442, 23401, 23360, 23318, 23277, 23235, 23193, 23150, 23106, ...
			23062, 23018, 22973, 22927, 22880, 22831, 22782, 22731, 22679, ...
			22626, 22570, 22513, 22454, 22393, 22329, 22264, 22196, 22125, ...
			22053, 21978, 21900, 21820, 21736, 21651, 21563, 21472, 21380, ...
			21285, 21189, 21091, 20990, 20889, 20786, 20682, 20578, 20474, ...
			20370, 20266, 20164, 20063, 19963, 19865, 19770, 19679, 19591, ...
			19507, 19427, 19351, 19282, 19218, 19161, 19111, 19067, 19031, ...
			18999, 18976, 18959, 18953, 18952, 18960, 18971, 19002, 19035, ...
			19075, 19120, 19174, 19238, 19301, 19372, 19460, 19545, 19637, ...
			19734, 19836, 19943, 20054, 20177, 20296, 20413, 20534, 20661, ...
			20783, 20907, 21034, 21161, 21281, 21397, 21515, 21638, 21750, ...
			21859, 21970, 22077, 22178, 22282, 22373, 22470, 22563, 22656, ...
			22745, 22832, 22916, 22996, 23076, 23156, 23235, 23310, 23388, ...
			23462, 23532, 23601, 23669, 23735, 23804, 23870, 23934, 23995, ...
			24057, 24120, 24183, 24243, 24302, 24360, 24418, 24475, 24531, ...
			24587, 24641, 24695, 24747, 24798, 24848, 24897, 24946, 24995, ...
			25043, 25088, 25131, 25172, 25214, 25255, 25294, 25332, 25367, ...
			25403, 25438, 25475, 25507, 25541, 25573, 25608, 25640, 25675, ...
			25711, 25746, 25783, 25823, 25865, 25909, 25954, 26002, 26053, ...
			26108, 26166, 26228, 26293, 26364, 26437, 26512, 26591, 26673, ...
			26758, 26848, 26941, 27037, 27136, 27235, 27336, 27440, 27545, ...
			27652, 27758, 27866, 27975, 28084, 28192, 28300, 28409, 28516, ...
			28623, 28728, 28832, 28934, 29036, 29135, 29233, 29328, 29421, ...
			29510, 29597, 29681, 29762, 29840, 29915, 29986, 30053, 30115, ...
			30173, 30227, 30277, 30323, 30364, 30400, 30432, 30459, 30481, ...
			30498, 30511, 30519, 30522, 30521, 30515, 30505, 30490, 30472, ...
			30449, 30423, 30392, 30358, 30321, 30281, 30237, 30190, 30140, ...
			30088, 30033, 29975, 29915, 29852, 29788, 29720, 29651, 29580, ...
			29506, 29431, 29353, 29274, 29193, 29110, 29026, 28940, 28853, ...
			28764, 28674, 28584, 28492, 28400, 28307, 28213, 28120, 28026, ...
			27932, 27839, 27746, 27654, 27562, 27472, 27383, 27294, 27207, ...
			27121, 27037, 26955, 26875, 26797, 26721, 26647, 26576, 26507, ...
			26441, 26377, 26316, 26258, 26202, 26148, 26096, 26047, 25999, ...
			25954, 25910, 25868, 25828, 25789, 25752, 25715, 25679, 25644, ...
			25608, 25574, 25539, 25497 ];

	WMM_F_600_km_longitude = [ -180, -179, -178, -177, -176, ...
			-175, -174, -173, -172, -171, -170, -169, -168, -167, -166, -165,....
			-164, -163, -162, -161, -160, -159, -158, -157, -156, -155, -154,....
			-153, -152, -151, -150, -149, -148, -147, -146, -145, -144, -143, ...
			-142, -141, -140, -139, -138, -137, -136, -135, -134, -133, -132, ...
			-131, -130, -129, -128, -127, -126, -125, -124, -123, -122, -121, ...
			-120, -119, -118, -117, -116, -115, -114, -113, -112, -111, -110, ...
			-109, -108, -107, -106, -105, -104, -103, -102, -101, -100, -99, ...
			-98, -97, -96, -95, -94, -93, -92, -91, -90, -89, -88, -87, -86, ...
			-85, -84, -83, -82, -81, -80, -79, -78, -77, -76, -75, -74, -73, ...
			-72, -71, -70, -69, -68, -67, -66, -65, -64, -63, -62, -61, -60, ...
			-59, -58, -57, -56, -55, -54, -53, -52, -51, -50, -49, -48, -47, ...
			-46, -45, -44, -43, -42, -41, -40, -39, -38, -37, -36, -35, -34, ...
			-33, -32, -31, -30, -29, -28, -27, -26, -25, -24, -23, -22, -21, ...
			-20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7,  ...
			-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, ...
			13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, ...
			30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, ...
			47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, ...
			64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, ...
			81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, ...
			98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, ...
			112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, ...
			125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, ...
			138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, ...
			151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, ...
			164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, ...
			177, 178, 179, 180 ];


 
fejer = interpn(dim1_f107,dim2_season,dim3_lt,dim4_longitude, Fejer1999, ...
    f107,season,lt,longitude,'linear');

this_wmm = interp1(WMM_F_600_km_longitude , WMM_F_600_km , longitude);

fejer = ( fejer * this_wmm ) / 1e6;